package cn.imokay.stopthread;

/**
 * run方法没有sleep和wait
 */
public class RightWayStopThreadWithoutSleep implements Runnable{
    @Override
    public void run() {
        //。输出10000的整数倍数
        int num = 0;
        while(!Thread.currentThread().isInterrupted() && num < Integer.MAX_VALUE/2){
            if (num % 10000 == 0) {
                System.out.println(num+"是10000的整数倍");
            }
            num++;
            System.out.println(Thread.currentThread().isInterrupted());
        }
        System.out.println("finished");
        System.out.println(Thread.currentThread().isInterrupted());
    }

    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(new RightWayStopThreadWithoutSleep());
        thread.start();
        Thread.sleep(1000);
        //通知中断
        thread.interrupt();
    }
}
